package com.specialized.orders.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.specialized.common.core.domain.Result;
import com.specialized.orders.common.domain.Distance;
import com.specialized.orders.common.domain.PickAirportVo.PickAirportVo;
import com.specialized.orders.utils.ChargRule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.specialized.common.security.annotation.RequiresPermissions;
import com.specialized.orders.common.domain.PickAirport;
import com.specialized.orders.service.IPickAirportService;
import com.specialized.common.core.web.controller.BaseController;
import com.specialized.common.core.utils.poi.ExcelUtil;

/**
 * 接机订单Controller
 *
 * @author djh
 * @date 2024-07-24
 */
@RestController
@RequestMapping("/pickAirport")
public class PickAirportController extends BaseController {
    @Autowired
    private IPickAirportService pickAirportService;

    /**
     * 查询接机订单列表
     */
    @GetMapping("/list")
    public Result list(PickAirport pickAirport) {
        startPage();
        List<PickAirport> list = pickAirportService.selectPickAirportList(pickAirport);
        return getDataTable(list);
    }

    /**
     * 查询接机订单列表
     */
    @GetMapping("/findAll")
    public Result findAll(PickAirport pickAirport) {
        startPage();
        List<PickAirportVo> list = pickAirportService.findListAll(pickAirport);
        return getDataTable(list);
    }

    /**
     * 导出接机订单列表
     */
//    @RequiresPermissions("orders:pickAirport:export")
//    @Log(title = "接机订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PickAirport pickAirport) {
        List<PickAirport> list = pickAirportService.selectPickAirportList(pickAirport);
        ExcelUtil<PickAirport> util = new ExcelUtil<PickAirport>(PickAirport. class);
        util.exportExcel(response, list, "接机订单数据");
    }

    /**
     * 获取接机订单详细信息
     */
//    @RequiresPermissions("orders:pickAirport:query")
    @GetMapping(value = "/{pickairportId}")
    public Result getInfo(@PathVariable("pickairportId") Long pickairportId) {
        return success(pickAirportService.selectPickAirportByPickairportId(pickairportId));
    }

    /**
     * 新增接机订单
     */
//    @Log(title = "接机订单", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody PickAirport pickAirport) {
        return pickAirportService.insertPickAirport(pickAirport);
    }

    /**
     * 修改接机订单
     */
//    @RequiresPermissions("orders:pickAirport:edit")
//    @Log(title = "接机订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody PickAirport pickAirport) {
        return toAjax(pickAirportService.updatePickAirport(pickAirport));
    }

    /**
     * 删除接机订单
     */
//    @RequiresPermissions("orders:pickAirport:remove")
//    @Log(title = "接机订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pickairportIds}")
    public Result remove(@PathVariable Long[] pickairportIds) {
        return toAjax(pickAirportService.deletePickAirportByPickairportIds(pickairportIds));
    }

    @GetMapping("findDist")
    public Result findDist(@RequestParam("oragin") String oragin, @RequestParam("destination") String destination){
        ChargRule chargRule = new ChargRule();
        Distance distance = chargRule.computeDistance(oragin, destination);
        return Result.success(distance);
    }

    /**
     * 结束订单
     * @param ordercard
     * @return
     */
    @GetMapping("/updateBYOrderCard/{orderCard}")
    public Result updateByOrderCard(@PathVariable("orderCard") String ordercard){
        return pickAirportService.updateByOrderCard(ordercard);
    }


}
